import Vue from 'vue'
import router from 'vue-router'
import store from '../store'
import HelloWorld from '@/components/HelloWorld'
import Login from '@/components/Login'
import AdminIndex from '../components/admin/AdminIndex.vue'

Vue.use(router);

//页面刷新时，重新赋值token
if(localStorage.getItem('token')){
  store.commit('set_token', localStorage.getItem('token'))
}

export default new router({
  // mode: 'history',
  routes: [
    {
      path: '/login',
      name: 'Login',
      component: Login
    },
    {
      path: '/admin',
      name: 'admin',
      component: AdminIndex,
    },
    {
      path: '*', // 页面不存在的情况下会跳到login页面
      redirect: '/admin',
      name: 'notFound',
      hidden: true
    }
  ]
});

